<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<c:set var="staffType" value="${param.staffType}" />
<c:set var="selfDeptState" value="${param.selfDeptState}" />
<c:set var="taskId" value="${param.taskId}" />
<c:set var="taskType" value="${param.taskType}" />
<c:set var="taskState" value="${param.taskState}" />
<c:set var="taskCostPrice" value="${param.taskCostPrice}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>提货单管理</title>
    <link rel="stylesheet" href="${ctx}/wx/css/default.css"/>
    <script type="text/javascript" src="${ctx}/wx/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/BillService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/TaskService.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
</head>
<body>
    <p class="contact-input">
        <span id="taskType" name="taskType"></span>
        <span id="taskSenderUserName" name="taskSenderUserName"></span>
        <span id="taskSenderUserMobile" name="taskSenderUserMobile"></span>
        <br>
        <span style="color: blue">装：</span>
        <span id="taskLoadingArea" name="taskLoadingArea"></span>
        <br>
        <span id="taskLoadingAddress" name="taskLoadingAddress"></span>
        <br>
        <span style="color: green">卸：</span>
        <span id="taskUnloadingArea" name="taskUnloadingArea"></span>
        <br>
        <span id="taskUnloadingAddress" name="taskUnloadingAddress"></span>
    </p>
    <c:if test="${taskState == 0 && selfDeptState == 1}">
        <p class="contact-submit">
            <input id="billButton" name="billButton" type="button" value="添加提货单" onclick="insertBill()">
        </p>
    </c:if>
    <SCRIPT LANGUAGE="JavaScript" type="">
        var billThead = new Array(
                new XThead("单号"),
                new XThead("状态"),
                new XThead("操作")
        );

        var billXTable = new XTable("bill", billThead, true);

        billXTable.XTbodyArray = function (model) {
            var href = "";
            <c:if test="${selfDeptState == 1}">
            if(model.billState == 0) {
                href = "<input type='button' value='确认收费' onclick=\"updateBillState1('" + model.billId + "', '" + model.billCode + "', 1)\">";
            } else if(model.billState == 1) {
                href = "<a href='${ctx}/wx/page/bill_print.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&taskId=${taskId}&taskType=${taskType}&taskCostPrice=${taskCostPrice}&taskState=${taskState}&billId=" + model.billId + "&billState=" + model.billState + "&billCode=" + model.billCode + "'><input type='button' value='打印'></a>";
            }
            </c:if>
            var array = new Array(
                    new XTbody("bill", "<a href='${ctx}/wx/page/bill_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&selfDeptState=${selfDeptState}&taskId=${taskId}&taskType=${taskType}&taskState=${taskState}&taskCostPrice=${taskCostPrice}&billId=" + model.billId + "&billState=" + model.billState + "'>" + model.billCode + "</a>", null, null, null, "center"),
                    new XTbody("bill", model.billState == 0 ? "待收费" : "已收费", null, null, null, "center"),
                    new XTbody("bill", href, null, null, null, "center")
            );

            return array;
        }
        billXTable.getXList = function (page){
            var bill = new Bill();
            bill.taskId = "${taskId}";
            BillService.selectBillList(bill, function(list){billXTable.addTable(list);});
        }
    </SCRIPT>
</body>
</html>
<script type="text/javascript">
    parent.document.title = "提货单管理";
    var task = new Task();
    task.taskId = "${taskId}";
    TaskService.selectTaskList(task, callbackSelectTaskList);
    function callbackSelectTaskList(list) {
        var task = list[0];
        dwr.util.setValues(task);
        dwr.util.setValue("taskType", task.taskType == 1 ? "煤贸" : task.taskType == 2 ? "运输" :"未知异常");

        billXTable.goPage(1);
    }

    function updateBillState1(billId, billCode, billState) {
        if (confirm("确认收费")) {
            var bill = new Bill();
            bill.taskId = "${taskId}";
            bill.billId = billId;
            bill.billCode = billCode;
            bill.billState = billState;
            BillService.updateBill(bill, function () {
                billXTable.goPage(1);
            });
        }
    }

    function insertBill() {
        location = "${ctx}/wx/page/bill_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&selfDeptState=${selfDeptState}&taskId=${taskId}&taskType=${taskType}&taskState=${taskState}&taskCostPrice=${taskCostPrice}&billState=0";
    }
</script>